﻿#include "mainwidget.h"
#include "ui_mainwidget.h"

#include <QDebug>

MainWidget::MainWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    qDebug()<<"ffmpeg ver = "<<avcodec_version();
    QStringList cameraNames = getCameraNames();
    if (cameraNames.isEmpty()){
        return ;
    }

    QString cameraName = QString("video=%1").arg(cameraNames.at(0));

    m_camera = new FCamera(this);
    m_camera->openDev(cameraName);
}

MainWidget::~MainWidget()
{
    delete ui;
}

QStringList MainWidget::getCameraNames()
{
    QStringList names;
    QList<QCameraInfo> cameraList = QCameraInfo::availableCameras();
    if (cameraList.isEmpty()){
        return names;
    }
    foreach (auto camera, cameraList) {
        names.append(camera.description());
        qDebug()<<"name = "<<camera.deviceName()<<"des = "<<camera.description();
    }

    return names;
}

